﻿using System;
using System.Configuration;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;

namespace SocketChat.Server
{
    public static class Program
    {
        //public static IPEndPoint IPEndPoint { get; set; } 

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //var setupForm = new SetUpForm();
            //var result = setupForm.ShowDialog();
            //if (result == DialogResult.OK)
            try {
                var endPoint = new IPEndPoint(IPAddress.Parse(ConfigurationManager.AppSettings["ip"]), int.Parse(ConfigurationManager.AppSettings["port"]));
                Application.Run(new MainForm(endPoint));
            }
            catch (OverflowException ex) {
                MessageBox.Show("端口错误!请修改配置文件!" + System.Environment.NewLine + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (FormatException ex) {
                MessageBox.Show("IP地址错误!请修改配置文件!" + System.Environment.NewLine + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (SocketException ex) {
                MessageBox.Show("端口被占用!" + System.Environment.NewLine + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
